package old_question_new_working;

/**
 * Author: 笨蛋超人不会飞
 * Date:  9:28
 */
public class q_42 {
}
//接雨水问题
class Solution_42 {
    public int trap(int[] height) {
        int len=height.length;
        int left[]=new int[len];
        int right[]=new int[len];
        int max=0;
        for (int i = 0; i < len; i++) {
            if(height[i]>max){
                max=height[i];
            }
            left[i]=max;

        }
        max=0;
        for (int i = len-1; i >=0; i--) {
            if(height[i]>max){
                max=height[i];
            }
            right[i]=max;
        }
        int result=0;
        for (int i = 1; i < len-1; i++) {
            int temp=left[i]>right[i]?right[i]:left[i];
            if(temp-height[i]>0){
                result+=temp;
            }
        }
        return result;

    }
}
